<?php 

class kendo_table{
    
    static function getProperty()
	{
		$obj = new stdClass();
		$limit = JRequest::getInt("take");
		$limitstart = JRequest::getInt("skip");			
		$filterval = "";
		$sortval = "";
		if(isset($_REQUEST['filter']))
		{
			$arr_filter = array();
			$filters = JRequest::getVar("filter");
			foreach($filters["filters"] as $filter)
			{
				$operator = $filter['operator'];
				switch($operator)
				{
					case "contains":
						$operator = "like";
						break;
					case "gte";
						$operator = ">=";
						break;	
					case "lte";
						$operator = "<=";
						break;
					case "eq";
						$operator = "=";
						break;
					case "gt";
						$operator = ">";
						break;
					case "lt";
						$operator = "<";
						break;					
				}
				if($operator == "like")
				{
					array_push($arr_filter,$filter['field'] ." $operator '%" . $filter['value'] . "%'");
				}else
				{
					array_push($arr_filter,$filter['field'] ." $operator '" . $filter['value'] . "'");
				}
				
			}
			if(count($filters["filters"]) > 1)
			{
				$filterval = join(' and ',$arr_filter);
			}else $filterval = join(' or ',$arr_filter);
		}
		if(isset($_REQUEST['sort']))
		{
			$sorts = JRequest::getVar("sort");
			$sortval = $sorts[0]['field'] . ' ' . $sorts[0]['dir'];
		}
		
		//filter data
		if(!empty($filterval))
		{
			$where = "  " . $filterval;
		}else $where = "";
		//sort data
		if(!empty($sortval))
		{
			$where .= " order by " . $sortval;
		}
		//echo $where;exit();
		$obj->limitstart = $limitstart;
		$obj->limit = $limit;
		$obj->where = $where;
		return $obj;
	}
	
	static function dataBinding()
	{
		if(isset($_REQUEST['take']))
			return true;
		else return false;	
	}
    
       
}

?>